class User {
  final String id;
  final String username;
  final String email;
  final String avatar;
  final String bio;
  final int followersCount;
  final int followingCount;
  final int watchCount;
  final String membershipType;
  final DateTime membershipExpiry;
  final bool isVerified;

  User({
    required this.id,
    required this.username,
    required this.email,
    required this.avatar,
    this.bio = '',
    this.followersCount = 0,
    this.followingCount = 0,
    this.watchCount = 0,
    this.membershipType = '普通会员',
    required this.membershipExpiry,
    this.isVerified = false,
  });

  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      id: json['id'],
      username: json['username'],
      email: json['email'],
      avatar: json['avatar'],
      bio: json['bio'] ?? '',
      followersCount: json['followers_count'] ?? 0,
      followingCount: json['following_count'] ?? 0,
      watchCount: json['watch_count'] ?? 0,
      membershipType: json['membership_type'] ?? '普通会员',
      membershipExpiry: DateTime.parse(json['membership_expiry']),
      isVerified: json['is_verified'] ?? false,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'username': username,
      'email': email,
      'avatar': avatar,
      'bio': bio,
      'followers_count': followersCount,
      'following_count': followingCount,
      'watch_count': watchCount,
      'membership_type': membershipType,
      'membership_expiry': membershipExpiry.toIso8601String(),
      'is_verified': isVerified,
    };
  }

  User copyWith({
    String? id,
    String? username,
    String? email,
    String? avatar,
    String? bio,
    int? followersCount,
    int? followingCount,
    int? watchCount,
    String? membershipType,
    DateTime? membershipExpiry,
    bool? isVerified,
  }) {
    return User(
      id: id ?? this.id,
      username: username ?? this.username,
      email: email ?? this.email,
      avatar: avatar ?? this.avatar,
      bio: bio ?? this.bio,
      followersCount: followersCount ?? this.followersCount,
      followingCount: followingCount ?? this.followingCount,
      watchCount: watchCount ?? this.watchCount,
      membershipType: membershipType ?? this.membershipType,
      membershipExpiry: membershipExpiry ?? this.membershipExpiry,
      isVerified: isVerified ?? this.isVerified,
    );
  }
}
